
<!DOCTYPE HTML>
<html lang="en" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>客户端AioQuickClient · smartboot 中文指南</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="7-AioSession.html" />
    
    
    <link rel="prev" href="5-AioQuickServer.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"smartboot","repo":"smart-socket","type":"star","size":"small","count":true}]};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    关于smartboot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    smart-socket 使用手册
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../quickStart.html">
            
                <a href="../quickStart.html">
            
                    
                    快速上手
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" >
            
                <span>
            
                    
                    源码篇
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.3.1" data-path="1-ready.html">
            
                <a href="1-ready.html">
            
                    
                    准备工作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.2" data-path="2-core-interface.html">
            
                <a href="2-core-interface.html">
            
                    
                    核心接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.3" data-path="3-enum.html">
            
                <a href="3-enum.html">
            
                    
                    枚举状态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.4" data-path="4-IoServerConfig.html">
            
                <a href="4-IoServerConfig.html">
            
                    
                    服务配置IoServerConfig
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.5" data-path="5-AioQuickServer.html">
            
                <a href="5-AioQuickServer.html">
            
                    
                    服务端AioQuickServer
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.3.6" data-path="6-AioQuickClient.html">
            
                <a href="6-AioQuickClient.html">
            
                    
                    客户端AioQuickClient
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.7" data-path="7-AioSession.html">
            
                <a href="7-AioSession.html">
            
                    
                    通信会话AioSession
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.8" data-path="8-CompletionHandler.html">
            
                <a href="8-CompletionHandler.html">
            
                    
                    读写回调
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.4" >
            
                <span>
            
                    
                    进阶篇
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.4.1" data-path="../second/readme.html">
            
                <a href="../second/readme.html">
            
                    
                    开篇概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.2" data-path="../second/2-decoder.html">
            
                <a href="../second/2-decoder.html">
            
                    
                    协议解码器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.3" data-path="../second/3-type-one.html">
            
                <a href="../second/3-type-one.html">
            
                    
                    一类消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.4" data-path="../second/4-type-two.html">
            
                <a href="../second/4-type-two.html">
            
                    
                    二类消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.5" data-path="../second/5-type-three.html">
            
                <a href="../second/5-type-three.html">
            
                    
                    三类消息
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.5" >
            
                <a target="_blank" href="https://smartboot.github.io/smart-socket/apidocs/index.html">
            
                    
                    API Docs
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    smart-ioc 使用手册
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    smart-boot 使用手册
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    mydalgen 使用手册
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    技术分享
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../../share/rpc/smart-socket-rpc.html">
            
                <a href="../../share/rpc/smart-socket-rpc.html">
            
                    
                    smart-socket实现RPC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../../share/exception/readme.html">
            
                <a href="../../share/exception/readme.html">
            
                    
                    Exception杂谈
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../../donation.html">
            
                <a href="../../donation.html">
            
                    
                    关于捐赠
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >客户端AioQuickClient</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x516D;&#x3001;&#x5BA2;&#x6237;&#x7AEF;aioquickclient">&#x516D;&#x3001;&#x5BA2;&#x6237;&#x7AEF;AioQuickClient</h1>
<h3 id="&#x6210;&#x5458;&#x5C5E;&#x6027;">&#x6210;&#x5458;&#x5C5E;&#x6027;</h3>
<table>
<thead>
<tr>
<th>&#x5C5E;&#x6027;&#x540D;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>socketChannel</td>
<td>AsynchronousSocketChannel</td>
<td>JDK&#x63D0;&#x4F9B;&#x7684;AIO&#x5BA2;&#x6237;&#x7AEF;&#x6838;&#x5FC3;&#x7C7B;</td>
</tr>
<tr>
<td>asynchronousChannelGroup</td>
<td>AsynchronousChannelGroup</td>
<td>JDK&#x4E3A;AIO&#x63D0;&#x4F9B;&#x7684;&#x7EBF;&#x7A0B;&#x6C60;&#x670D;&#x52A1;</td>
</tr>
<tr>
<td>config</td>
<td>IoServerConfig</td>
<td>&#x5B58;&#x50A8;AioQuickClient&#x670D;&#x52A1;&#x914D;&#x7F6E;&#x9879;</td>
</tr>
</tbody>
</table>
<h3 id="&#x914D;&#x7F6E;&#x578B;&#x65B9;&#x6CD5;">&#x914D;&#x7F6E;&#x578B;&#x65B9;&#x6CD5;</h3>
<table>
<thead>
<tr>
<th>&#x65B9;&#x6CD5;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>public AioQuickClient<t> connect(String host, int port)</t></td>
<td>&#x8BBE;&#x7F6E;&#x8FDC;&#x7A0B;&#x8FDE;&#x63A5;&#x7684;&#x5730;&#x5740;&#x3001;&#x7AEF;&#x53E3;</td>
</tr>
<tr>
<td>public AioQuickClient<t> setProtocol(Protocol<t> protocol)</t></t></td>
<td>&#x6CE8;&#x518C;&#x534F;&#x8BAE;&#x7F16;&#x89E3;&#x7801;&#x5B9E;&#x73B0;</td>
</tr>
<tr>
<td>public AioQuickClient<t> setFilters(Filter<t>[] filters)</t></t></td>
<td>&#x6CE8;&#x518C;&#x670D;&#x52A1;&#x8FC7;&#x6EE4;&#x5668;</td>
</tr>
<tr>
<td>public AioQuickClient<t> setProcessor(MessageProcessor<t> processor)</t></t></td>
<td>&#x6CE8;&#x518C;&#x4E1A;&#x52A1;&#x5904;&#x7406;&#x5668;</td>
</tr>
<tr>
<td>public AioQuickClient<t> setReadBufferSize(int size)</t></td>
<td>&#x8BBE;&#x7F6E;&#x8BFB;&#x7F13;&#x51B2;&#x533A;&#x5927;&#x5C0F;</td>
</tr>
<tr>
<td>public AioQuickClient<t> setWriteQueueSize(int size)</t></td>
<td>&#x8BBE;&#x7F6E;AioSession&#x8F93;&#x51FA;&#x7F13;&#x5B58;&#x533A;&#x961F;&#x5217;&#x957F;&#x5EA6;</td>
</tr>
</tbody>
</table>
<h3 id="&#x6838;&#x5FC3;&#x65B9;&#x6CD5;">&#x6838;&#x5FC3;&#x65B9;&#x6CD5;</h3>
<h4 id="1&#x3001;startasynchronouschannelgroup-asynchronouschannelgroup&#xFF1A;-&#x542F;&#x52A8;aio&#x5BA2;&#x6237;&#x7AEF;&#x670D;&#x52A1;">1&#x3001;start(AsynchronousChannelGroup asynchronousChannelGroup)&#xFF1A; &#x542F;&#x52A8;AIO&#x5BA2;&#x6237;&#x7AEF;&#x670D;&#x52A1;</h4>
<pre><code>public void start(AsynchronousChannelGroup asynchronousChannelGroup) throws IOException, ExecutionException, InterruptedException {
        this.socketChannel = AsynchronousSocketChannel.open(asynchronousChannelGroup);
        socketChannel.connect(new InetSocketAddress(config.getHost(), config.getPort())).get();
        //&#x8FDE;&#x63A5;&#x6210;&#x529F;&#x5219;&#x6784;&#x9020;AIOSession&#x5BF9;&#x8C61;
        AioSession session = new AioSession&lt;T&gt;(socketChannel, config, new ReadCompletionHandler(), new WriteCompletionHandler(), false);
        session.initSession();
}
</code></pre><p>&#x8BE5;&#x65B9;&#x6CD5;&#x652F;&#x6301;&#x5916;&#x90E8;&#x4F20;&#x5165;&#x670D;&#x52A1;&#x7EBF;&#x7A0B;&#x7EC4;<code>AsynchronousChannelGroup</code>&#xFF0C;&#x5F53;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#x8981;&#x542F;&#x52A8;&#x591A;&#x4E2A;&#x5BA2;&#x6237;&#x7AEF;&#x65F6;&#xFF0C;&#x91C7;&#x7528;&#x8BE5;&#x65B9;&#x5F0F;&#x6709;&#x52A9;&#x4E8E;&#x63D0;&#x5347;&#x8D44;&#x6E90;&#x5229;&#x7528;&#x7387;&#x3002;<br>&#x5BA2;&#x6237;&#x7AEF;&#x8FDE;&#x63A5;&#x670D;&#x52A1;&#x5668;&#x7684;&#x8FC7;&#x7A0B;&#x5E76;&#x6CA1;&#x6709;&#x91C7;&#x7528;<code>CompletionHandler</code>&#x7684;&#x65B9;&#x6848;&#xFF0C;&#x662F;&#x56E0;&#x4E3A;&#x4F5C;&#x8005;&#x8BA4;&#x4E3A;&#x4F5C;&#x4E3A;&#x5BA2;&#x6237;&#x7AEF;&#xFF0C;&#x91C7;&#x7528;<code>Future</code>&#x6A21;&#x5F0F;&#x53EF;&#x4EE5;&#x964D;&#x4F4E;&#x4EE3;&#x7801;&#x590D;&#x6742;&#x5EA6;&#xFF0C;&#x63A5;&#x53E3;&#x529F;&#x80FD;&#x66F4;&#x76F4;&#x89C2;&#x3002;&#x56E0;&#x4E3A;&#x5BF9;&#x4E8E;&#x4E1A;&#x52A1;&#x6765;&#x8BF4;&#xFF0C;&#x4E00;&#x65E6;start&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#xFF0C;&#x8FDE;&#x63A5;&#x5C31;&#x5FC5;&#x987B;&#x662F;&#x5EFA;&#x7ACB;&#x6210;&#x529F;&#x7684;&#x3002;<br>&#x7F51;&#x7EDC;&#x8FDE;&#x63A5;&#x5EFA;&#x7ACB;&#x5B8C;&#x6BD5;&#x4E4B;&#x540E;&#xFF0C;&#x5C31;&#x4F1A;&#x6784;&#x5EFA;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x901A;&#x4FE1;&#x4F1A;&#x8BDD;AioSession&#x3002;</p>
<h4 id="2&#x3001;start">2&#x3001;start()</h4>
<pre><code>  public void start() throws IOException, ExecutionException, InterruptedException {
        this.asynchronousChannelGroup = AsynchronousChannelGroup.withFixedThreadPool(2, new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r);
            }
        });
        start(asynchronousChannelGroup);
    }
</code></pre><p>&#x5982;&#x679C;&#x5BA2;&#x6237;&#x7AEF;&#x8981;&#x4F7F;&#x7528;&#x79C1;&#x6709;&#x7684;&#x7EBF;&#x7A0B;&#x7EC4;&#xFF0C;&#x53EF;&#x8C03;&#x7528;&#x4E0D;&#x5E26;&#x53C2;&#x6570;&#x7684;start&#x65B9;&#x6CD5;&#x3002;&#x5355;&#x5BA2;&#x6237;&#x7AEF;&#x53EA;&#x6709;&#x8BFB;&#x3001;&#x5199;&#x4E24;&#x7C7B;&#x64CD;&#x4F5C;&#xFF0C;&#x6240;&#x4EE5;&#x7EBF;&#x7A0B;&#x5927;&#x5C0F;&#x8BBE;&#x7F6E;&#x4E3A;2&#x8DB3;&#x77E3;&#x3002;&#x4E14;&#x79C1;&#x6709;&#x7684;&#x7EBF;&#x7A0B;&#x7EC4;&#x9700;&#x8981;&#x8D4B;&#x503C;&#x4E8E;&#x6210;&#x5458;&#x5C5E;&#x6027;<code>asynchronousChannelGroup</code>,&#x4EE5;&#x4FBF;&#x5BA2;&#x6237;&#x7AEF;&#x6267;&#x884C;shutdown&#x65F6;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x8D44;&#x6E90;&#x91CA;&#x653E;&#x3002;</p>
<h4 id="3&#x3001;shutdown">3&#x3001;shutdown()</h4>
<p>&#x4EE3;&#x7801;&#x7B80;&#x5355;&#xFF0C;&#x4E0D;&#x89E3;&#x91CA;</p>
<pre><code>public void shutdown() {
        if (socketChannel != null) {
            try {
                socketChannel.close();
            } catch (IOException e) {
                LOGGER.catching(e);
            }
        }
        //&#x4EC5;Client&#x5185;&#x90E8;&#x521B;&#x5EFA;&#x7684;ChannelGroup&#x9700;&#x8981;shutdown
        if (asynchronousChannelGroup != null) {
            asynchronousChannelGroup.shutdown();
        }
    }
</code></pre><footer class="page-footer"><span class="copyright">Copyright &#xA9; smartboot.org 2018 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2018-05-27 14:34:42
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="5-AioQuickServer.html" class="navigation navigation-prev " aria-label="Previous page: 服务端AioQuickServer">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="7-AioSession.html" class="navigation navigation-next " aria-label="Next page: 通信会话AioSession">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"客户端AioQuickClient","level":"1.2.3.6","depth":3,"next":{"title":"通信会话AioSession","level":"1.2.3.7","depth":3,"path":"smart-socket/first/7-AioSession.md","ref":"smart-socket/first/7-AioSession.md","articles":[]},"previous":{"title":"服务端AioQuickServer","level":"1.2.3.5","depth":3,"path":"smart-socket/first/5-AioQuickServer.md","ref":"smart-socket/first/5-AioQuickServer.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","-sharing","search-plus","expandable-chapters-interactive","tbfed-pagefooter","github","github-buttons","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy smartboot.org 2018","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"github":{"url":"https://github.com/smartboot/smart-socket"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"expandable-chapters-interactive":{},"github-buttons":{"buttons":[{"user":"smartboot","repo":"smart-socket","type":"star","size":"small","count":true}]},"edit-link":{"label":"Edit This Page","base":"https://gitee.com/smartboot/docs/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"smartboot 中文指南","language":"en","gitbook":"*","description":"本文涵盖了smartboot下所有项目的技术手册"},"file":{"path":"smart-socket/first/6-AioQuickClient.md","mtime":"2018-05-27T06:34:42.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2018-09-23T08:59:34.607Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

